package com.zzyl.common.ai;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.ResponseFormatJsonObject;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;

public class AIModelTest {
    public static void main(String[] args) {

            OpenAIClient client = OpenAIOkHttpClient.builder()
                    .apiKey("bce-v3/ALTAK-1XpNFS02lODT2ilRh07X4/25d27637f0b60f58737abe2dc21a72fa151ec9bd") //将your_APIKey替换为真实值，如何获取API Key请查看https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps#步骤二-获取api-key
                    .baseUrl("https://qianfan.baidubce.com/v2/") //千帆ModelBuilder平台地址
                    .build();

            ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
                    .addUserMessage("你好，请帮我写一首诗，赞美张甜甜!") // 对话messages信息
                    .model("deepseek-r1") // 模型对应的model值，请查看支持的模型列表：https://cloud.baidu.com/doc/WENXINWORKSHOP/s/wm7ltcvgc
                    .responseFormat(ChatCompletionCreateParams.ResponseFormat.ofJsonObject(ResponseFormatJsonObject.builder().build()))
                    .build();

            ChatCompletion chatCompletion = client.chat().completions().create(params);
            System.out.println(chatCompletion.choices().get(0).message().content());
        }
    }
